package com.qt.myio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @Author zsf
 * @Date 2023/9/21 23:53
 * @Version 1.0
 */
public class MyIoDemo02 {

    public static void main(String[] args) throws IOException {

        //extracted();

        //extracted1();



        //extracted2();


    }

    private static void extracted2() throws IOException {

        /**
         * 多字节读取写入
         */
        long start = System.currentTimeMillis();
        FileInputStream fis = new FileInputStream("aaa\\a.txt");
        FileOutputStream fos = new FileOutputStream("aaa\\b.txt");
        int len;
        byte[] bytes = new byte[1024 * 1024 * 5];
        while ((len = fis.read(bytes)) != -1){
            fos.write(bytes,0,len);
        }
        fos.close();
        fis.close();

        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }

    private static void extracted1() throws IOException {
        /**
         * 文件拷贝----单字节拷贝
         */

        FileInputStream fir = new FileInputStream("aaa\\a.txt");
        FileOutputStream fow = new FileOutputStream("aaa\\b.txt");

        long l = System.currentTimeMillis();
        int b;
        while ((b = fir.read()) != -1){
            fow.write(b);
        }
        fow.close();
        fir.close();
        long l2 = System.currentTimeMillis();
        System.out.println("耗时:"+(l2-l)+"毫秒");
    }

    private static void extracted() throws IOException {
        /**
         * 循环读写
         */

        FileInputStream fit = new FileInputStream("aaa\\a.txt");
        int b;
        while ((b = fit.read()) != -1){
            System.out.println(b);
        }

        fit.close();
    }

}
